package com.wc.alorithm_blue_bridge._动态规划.背包问题.Q1174;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Author congge
 * @Date 2023/10/29 21:17
 * @description 典型的背包问题
 * 小明的背包1
 * https://www.lanqiao.cn/problems/1174/learning/?page=1&first_category_id=1&sort=students_count&second_category_id=8
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();

        int n = sc.nextInt();
        int tank = sc.nextInt();
        int[][] dp = new int[n][tank + 1];
        int[] ws = new int[n];
        int[] vs = new int[n];
        for (int i = 0; i < n; i++) {
            int w = sc.nextInt();
            int v = sc.nextInt();
            ws[i] = w;
            vs[i] = v;
        }

        for (int i = ws[0]; i <= tank; i++) {
            dp[0][i] = vs[0];
        }

        for (int i = 1; i < n; i++) {
            for (int j = 1; j <= tank; j++) {
                if (j >= ws[i]) {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - ws[i]] + vs[i]);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        System.out.println(dp[n - 1][tank]);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
